package com.liaowei.user.controller;

import com.liaowei.common.BaseResponse;
import com.liaowei.common.ResultUtils;
import com.liaowei.user.service.UserArticleHistoryService;
import com.liaowei.user.service.UserPostHistoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("histories")
@Validated
@RequiredArgsConstructor
public class UserHistoryController {

    private final UserArticleHistoryService articleHistoryService;
    private final UserPostHistoryService postHistoryService;


    // 删除用户所有的历史记录
    @DeleteMapping("{userId}")
    public BaseResponse<String> deleteAllHistory(@PathVariable @NotNull(message = "id不能为空") Long userId){
        articleHistoryService.removeAllArticleHistoryByUserId(userId);
        postHistoryService.removeAllPostHistoryByUserId(userId);
        return ResultUtils.success("删除成功");
    }

}
